
/*
 * Include Files
 *
 */
#if defined(MATLAB_MEX_FILE)
#include "tmwtypes.h"
#include "simstruc_types.h"
#else
#define SIMPLIFIED_RTWTYPES_COMPATIBILITY
#include "rtwtypes.h"
#undef SIMPLIFIED_RTWTYPES_COMPATIBILITY
#endif



/* %%%-SFUNWIZ_wrapper_includes_Changes_BEGIN --- EDIT HERE TO _END */
#include <math.h>
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define u_width 1
#define u_1_width 1
#define u_2_width 1
#define y_width 3

/*
 * Create external references here.  
 *
 */
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
 
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */

/*
 * Output function
 *
 */
void svpwm_Outputs_wrapper(const real32_T *u_alpha,
			const real32_T *u_beta,
			const real32_T *Vdc,
			real32_T *CMP)
{
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_BEGIN --- EDIT HERE TO _END */
float Vmax_pu = 0, Vmin_pu = 0, Vcom_pu;
  float oneOverDcBus_invV = 1 / *Vdc;

  float Valpha_pu = *u_alpha * oneOverDcBus_invV;
  float Vbeta_pu = *u_beta * oneOverDcBus_invV;

  float Va_tmp = (0.5f) * Valpha_pu;
  float Vb_tmp = sqrt(3) / 2 * Vbeta_pu;
  float Va_pu = Valpha_pu;


  float Vb_pu = -Va_tmp + Vb_tmp;
  float Vc_pu = -Va_tmp - Vb_tmp;

  if(Va_pu > Vb_pu)
  {
      Vmax_pu = Va_pu;
      Vmin_pu = Vb_pu;
  }
  else
  {
    Vmax_pu = Vb_pu;
    Vmin_pu = Va_pu;
  }
  
  if(Vc_pu > Vmax_pu)
  {
      Vmax_pu = Vc_pu;
  }
  else if(Vc_pu < Vmin_pu)
  {
      Vmin_pu = Vc_pu;
  }
  

  Vcom_pu = 0.5f * (Vmax_pu + Vmin_pu);

  CMP[0] = (Va_pu - Vcom_pu);
  CMP[1] = (Vb_pu - Vcom_pu);
  CMP[2] = (Vc_pu - Vcom_pu);
/* %%%-SFUNWIZ_wrapper_Outputs_Changes_END --- EDIT HERE TO _BEGIN */
}


